Skip to content

Fix scoped context and conflicting properties#263

Open
mielvds wants to merge 11 commits into
masterfrom
204-conflicting-value-override
Open

Fix scoped context and conflicting properties#263
mielvds wants to merge 11 commits into
masterfrom
204-conflicting-value-override

Conversation

@mielvds
Copy link
Copy Markdown
Collaborator

@mielvds mielvds commented May 12, 2026

This PR fixes #204 and two related tests in the test-suite:

https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#tc037

Nesting terms may have property-scoped contexts defined.

https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#tc038

Nesting terms may have property-scoped contexts defined.

The issue was that @nest keys were delayed for later expansion before their property-scoped context was applied. This fix first gets the scoped @context from the @nest term and stores this property-scoped context with the key. The delayed nested object expansion then later uses that property-scoped context, so for

{
  "@context": {
    "@vocab": "http://example.org/vocab#",
    "p1": {
      "@id": "@nest",
      "@context": {
        "p2": "http://example.org/ns#P2"
      }
    }
  },
  "p1": {
    "p2": "foo"
  }
}

"p2" expands to http://example.org/ns#P2 instead of falling back to outer @vocab.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

@mielvds mielvds marked this pull request as ready for review May 12, 2026 19:30
@PonteIneptique
Copy link
Copy Markdown

The tests correspond to the initial issue 👍 Thanks for your work !

@anatoly-scherbakov
Copy link
Copy Markdown
Collaborator

The changes might alter behavior in regard to nested contexts. I just pushed a test to this branch which aims to demonstrate that. I am sorry for pushing for a branch that's not mine, I will rather create a new, derived branch the next time @mielvds - I hope this won't create too much of an inconvenience.

@mielvds mielvds force-pushed the 204-conflicting-value-override branch from 2e9a89e to 7aa493a Compare May 18, 2026 08:57
@mielvds
Copy link
Copy Markdown
Collaborator Author

mielvds commented May 18, 2026

The changes might alter behavior in regard to nested contexts. I just pushed a test to this branch which aims to demonstrate that. I am sorry for pushing for a branch that's not mine, I will rather create a new, derived branch the next time @mielvds - I hope this won't create too much of an inconvenience.

Not at all @anatoly-scherbakov! Could you propagate this test to the JSON-LD test-suite? 🙏

I moved some of the docstring around to where it fits best. Most of it made more sense in the actual code. I added an internal method _prepare_nested_context that handles these complex cases, which is basically moving the logic for finding the active type-scoped context from _expand() and calling it in the loop that I included in the original fix.

@anatoly-scherbakov
Copy link
Copy Markdown
Collaborator

Propagated the nested scoped-context regression to the JSON-LD API test suite: w3c/json-ld-api#689

@mielvds mielvds force-pushed the 204-conflicting-value-override branch from e82e5a1 to 3d42075 Compare May 19, 2026 04:43
@mielvds
Copy link
Copy Markdown
Collaborator Author

mielvds commented May 19, 2026

@anatoly-scherbakov thanks! I did some final cleanup. It could still use a (minor) code review though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nested node with own vocab has conflicting value overriden

3 participants